package org.com.coolfish.service;


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAdjusters;
import java.util.Calendar;
import java.util.Date;

public class TimeService {

	/*public static String nextMonthLastDay() {
 		
 		LocalDate nextMonth = LocalDate.now().plusMonths(1);
 		LocalDate endDayNextMonth = nextMonth.with(TemporalAdjusters.lastDayOfMonth());
 	
 		return endDayNextMonth.toString();
 	}
	*/
	
	
	public static Date monthLastDay() {
		
		LocalDate today = LocalDate.now().plusMonths(0);
		// 取本月第1天： 
		LocalDate firstDayOfThisMonth = today.with(TemporalAdjusters.firstDayOfMonth()); 
		// 取本月第26天：
		LocalDate secondDayOfThisMonth = firstDayOfThisMonth.withDayOfMonth(26); 
		ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = secondDayOfThisMonth.atTime(23, 59, 59);
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
		return date;
				
						
	}
	
	public static Date nextMonthFirstDay() {
		LocalDate today = LocalDate.now().plusMonths(0);
		// 取本月第1天： 
		LocalDate firstDayOfThisMonth = today.with(TemporalAdjusters.firstDayOfMonth()); 
		// 取本月第27天：联通27日开始
		LocalDate secondDayOfThisMonth = firstDayOfThisMonth.withDayOfMonth(27); 
		ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = secondDayOfThisMonth.atTime(0, 0, 0);
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
		return date;
	
	}
	
	public static Date nextMonthLastDay() {
 		
		LocalDate today = LocalDate.now().plusMonths(1);
		// 取下月第1天： 
		LocalDate firstDayOfThisMonth = today.with(TemporalAdjusters.firstDayOfMonth()); 
		// 取下月月第26天：联通26日结束
		LocalDate secondDayOfThisMonth = firstDayOfThisMonth.withDayOfMonth(26); 
		ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = secondDayOfThisMonth.atTime(23, 59, 59);
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
		return date;
 	}
	
	
	public static Date SecondMonthFirstDay() {
		LocalDate today = LocalDate.now().plusMonths(2);
		// 取下下月第1天： 
		LocalDate firstDayOfThisMonth = today.with(TemporalAdjusters.firstDayOfMonth()); 
		// 取下下月第27天：联通27日开始
		LocalDate secondDayOfThisMonth = firstDayOfThisMonth.withDayOfMonth(27); 
		ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = secondDayOfThisMonth.atTime(0, 0, 0);
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
		return date;
	}
	
	public static Date SecondMonthLastDay() {
 		

		LocalDate today = LocalDate.now().plusMonths(2);
		// 取下下月第1天： 
		LocalDate firstDayOfThisMonth = today.with(TemporalAdjusters.firstDayOfMonth()); 
		// 取下下月月第26天：联通26日结束
		LocalDate secondDayOfThisMonth = firstDayOfThisMonth.withDayOfMonth(26); 
		ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = secondDayOfThisMonth.atTime(23, 59, 59);
        ZonedDateTime zdt = localDateTime.atZone(zoneId);
        Date date = Date.from(zdt.toInstant());
        
		return date;
 	}
	
	
	
	
	
	public static void pring() {
		Calendar calendar = Calendar.getInstance();
	//	calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		Date firstDayOfMonth = calendar.getTime(); 
		
		//6月末
		calendar.add(Calendar.MONTH, 2);
		calendar.add(Calendar.DAY_OF_MONTH, -1);
		Date lastDayOfMonth = calendar.getTime();
		System.out.println(firstDayOfMonth);
		System.out.println(lastDayOfMonth);
		/*Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.DAY_OF_MONTH, 3);
		// 将小时至0
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		// 将分钟至0
		calendar.set(Calendar.MINUTE, 0);
		// 将秒至0
		calendar.set(Calendar.SECOND, 0);
		// 将毫秒至0
		calendar.set(Calendar.MILLISECOND, 0);
		calendar.add(Calendar.MILLISECOND, -1);
		Date lastDayOfMonth = calendar.getTime();
		System.out.println(lastDayOfMonth);*/
	}
	
}
